package algorithm;

public class leetcode_0058 {
    public int lengthOfLastWord(String s) {
        int len=s.length();
        int num=0;
        boolean flag=false;
        for(int i=len-1;i>=0;--i){
            char a=s.charAt(i);
            if(a!=' '){
                flag=true;
                num+=1;
            }
            if(flag&&a==' ') break;
        }
        return num;
    }
}
